from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-03-26 14:11:26.737364
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 26, Mar, 2021
Time: 14:11:31
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.1258
Nobs: 242.000 HQIC: -47.9006
Log likelihood: 2858.77 FPE: 9.33684e-22
AIC: -48.4233 Det(Omega_mle): 6.48535e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.449289 0.129464 3.470 0.001
L1.Burgenland 0.070380 0.063883 1.102 0.271
L1.Kärnten -0.217411 0.055257 -3.935 0.000
L1.Niederösterreich 0.084328 0.143004 0.590 0.555
L1.Oberösterreich 0.216529 0.132813 1.630 0.103
L1.Salzburg 0.263427 0.071629 3.678 0.000
L1.Steiermark 0.145563 0.093937 1.550 0.121
L1.Tirol 0.115621 0.062806 1.841 0.066
L1.Vorarlberg -0.030937 0.058281 -0.531 0.596
L1.Wien -0.082972 0.119349 -0.695 0.487
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.477539 0.154639 3.088 0.002
L1.Burgenland 0.006989 0.076306 0.092 0.927
L1.Kärnten 0.339301 0.066003 5.141 0.000
L1.Niederösterreich 0.111044 0.170812 0.650 0.516
L1.Oberösterreich -0.086371 0.158639 -0.544 0.586
L1.Salzburg 0.211342 0.085558 2.470 0.014
L1.Steiermark 0.133819 0.112204 1.193 0.233
L1.Tirol 0.136257 0.075019 1.816 0.069
L1.Vorarlberg 0.153774 0.069614 2.209 0.027
L1.Wien -0.471100 0.142558 -3.305 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.305981 0.062371 4.906 0.000
L1.Burgenland 0.094862 0.030776 3.082 0.002
L1.Kärnten -0.020352 0.026621 -0.765 0.445
L1.Niederösterreich 0.032614 0.068894 0.473 0.636
L1.Oberösterreich 0.300083 0.063984 4.690 0.000
L1.Salzburg 0.013074 0.034508 0.379 0.705
L1.Steiermark 0.015702 0.045255 0.347 0.729
L1.Tirol 0.070470 0.030257 2.329 0.020
L1.Vorarlberg 0.088806 0.028077 3.163 0.002
L1.Wien 0.105216 0.057498 1.830 0.067
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.210641 0.064553 3.263 0.001
L1.Burgenland 0.020793 0.031854 0.653 0.514
L1.Kärnten 0.009283 0.027553 0.337 0.736
L1.Niederösterreich 0.047667 0.071305 0.668 0.504
L1.Oberösterreich 0.398265 0.066223 6.014 0.000
L1.Salzburg 0.081818 0.035716 2.291 0.022
L1.Steiermark 0.142693 0.046839 3.046 0.002
L1.Tirol 0.047043 0.031316 1.502 0.133
L1.Vorarlberg 0.080214 0.029060 2.760 0.006
L1.Wien -0.038441 0.059510 -0.646 0.518
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.520007 0.126192 4.121 0.000
L1.Burgenland 0.080971 0.062269 1.300 0.193
L1.Kärnten 0.007106 0.053861 0.132 0.895
L1.Niederösterreich -0.043306 0.139390 -0.311 0.756
L1.Oberösterreich 0.142181 0.129456 1.098 0.272
L1.Salzburg 0.051206 0.069819 0.733 0.463
L1.Steiermark 0.093017 0.091563 1.016 0.310
L1.Tirol 0.214557 0.061219 3.505 0.000
L1.Vorarlberg 0.034811 0.056808 0.613 0.540
L1.Wien -0.090481 0.116333 -0.778 0.437
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.198610 0.095893 2.071 0.038
L1.Burgenland -0.019817 0.047318 -0.419 0.675
L1.Kärnten -0.024636 0.040929 -0.602 0.547
L1.Niederösterreich -0.049937 0.105922 -0.471 0.637
L1.Oberösterreich 0.438490 0.098373 4.457 0.000
L1.Salzburg 0.004682 0.053055 0.088 0.930
L1.Steiermark -0.007919 0.069578 -0.114 0.909
L1.Tirol 0.163660 0.046520 3.518 0.000
L1.Vorarlberg 0.060608 0.043168 1.404 0.160
L1.Wien 0.242692 0.088401 2.745 0.006
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.245209 0.122130 2.008 0.045
L1.Burgenland 0.019236 0.060264 0.319 0.750
L1.Kärnten -0.061644 0.052127 -1.183 0.237
L1.Niederösterreich -0.053532 0.134903 -0.397 0.692
L1.Oberösterreich 0.008676 0.125289 0.069 0.945
L1.Salzburg 0.076364 0.067572 1.130 0.258
L1.Steiermark 0.344844 0.088616 3.891 0.000
L1.Tirol 0.455315 0.059248 7.685 0.000
L1.Vorarlberg 0.147147 0.054979 2.676 0.007
L1.Wien -0.176473 0.112588 -1.567 0.117
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.121037 0.143357 0.844 0.399
L1.Burgenland 0.050316 0.070739 0.711 0.477
L1.Kärnten -0.062007 0.061188 -1.013 0.311
L1.Niederösterreich 0.218945 0.158351 1.383 0.167
L1.Oberösterreich -0.030789 0.147066 -0.209 0.834
L1.Salzburg 0.208638 0.079317 2.630 0.009
L1.Steiermark 0.136639 0.104018 1.314 0.189
L1.Tirol 0.047997 0.069546 0.690 0.490
L1.Vorarlberg 0.092778 0.064535 1.438 0.151
L1.Wien 0.218977 0.132157 1.657 0.098
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.587879 0.078077 7.529 0.000
L1.Burgenland -0.040908 0.038527 -1.062 0.288
L1.Kärnten -0.025963 0.033325 -0.779 0.436
L1.Niederösterreich 0.010750 0.086243 0.125 0.901
L1.Oberösterreich 0.331712 0.080097 4.141 0.000
L1.Salzburg 0.017954 0.043198 0.416 0.678
L1.Steiermark -0.030970 0.056652 -0.547 0.585
L1.Tirol 0.086643 0.037877 2.287 0.022
L1.Vorarlberg 0.112685 0.035148 3.206 0.001
L1.Wien -0.041348 0.071977 -0.574 0.566
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.134665 0.032505 0.158450 0.214976 0.050882 0.076083 -0.001463 0.154177
Kärnten 0.134665 1.000000 0.016071 0.205877 0.176887 -0.069574 0.156146 0.021918 0.307325
Niederösterreich 0.032505 0.016071 1.000000 0.254722 0.059256 0.277984 0.139727 0.042168 0.307555
Oberösterreich 0.158450 0.205877 0.254722 1.000000 0.302780 0.282537 0.086564 0.055407 0.135646
Salzburg 0.214976 0.176887 0.059256 0.302780 1.000000 0.149634 0.048104 0.095766 -0.001545
Steiermark 0.050882 -0.069574 0.277984 0.282537 0.149634 1.000000 0.109566 0.108125 -0.130271
Tirol 0.076083 0.156146 0.139727 0.086564 0.048104 0.109566 1.000000 0.165103 0.146883
Vorarlberg -0.001463 0.021918 0.042168 0.055407 0.095766 0.108125 0.165103 1.000000 0.000983
Wien 0.154177 0.307325 0.307555 0.135646 -0.001545 -0.130271 0.146883 0.000983 1.000000